﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Yaml.Presentation.Parsing {
    public class Indentation {
        /// <summary>
        /// Previous indentation levels (in spaces)
        /// </summary>
        private Stack<int> indentation;

        public Indentation() {
            indentation = new Stack<int>();
            indentation.Push(-1);
        }

        /// <summary>
        /// The level of indentation for the current block (in spaces).
        /// </summary>
        public int Current { get { return indentation.Peek(); } }

        /// <summary>
        /// Add a level of indent to the stack but only if it is greater than the current level
        /// </summary>
        /// <param name="column">The number of spaces of the new indent to add</param>
        /// <returns>True if the indentation was added, false if it was the same as the current one already there.</returns>
        public bool Push(int column) {
            if (column < Current) {
                throw new ArgumentException("Invalid indentation level, " + column, "column");
            }
            if (column > Current) {
                indentation.Push(column);
                return true;
            }
            return false;
        }

        /// <summary>
        /// Remove the top level of indentation and return the number of spaces for that indent.
        /// </summary>
        /// <returns></returns>
        public int Pop() {
            return indentation.Pop();
        }

    }
}
